NS=demo-ns
POD_NAME_PREFIX=demo-pod-name-prefix
MMIN=60
if [ -n "$1" ]; then
	NS=$1
fi
if [ -n "$2" ]; then
        POD_NAME_PREFIX=$2
fi
if [ -n "$3" ]; then
        MMIN=$3
fi

POLL_DIR=/log/user
LOG_NAME_PATTER=*.log*
TX_NO=`cat /proc/sys/kernel/random/uuid`
echo $TX_NO
mkdir $TX_NO
for containerName in `kubectl get po -n $NS |grep "$POD_NAME_PREFIX" | awk '{print $1}'`; do
	echo "Process container-> $containerName"
	mkdir $TX_NO/$containerName
	kubectl -n $NS exec $containerName -- mkdir -p /poll-log/$TX_NO
	kubectl -n $NS exec $containerName -- sh -c "find $POLL_DIR -mmin -$MMIN -name '$LOG_NAME_PATTER'| xargs -i cp {} /poll-log/$TX_NO/"
	kubectl cp $NS/$containerName:/poll-log/$TX_NO $TX_NO/$containerName
	kubectl -n $NS exec $containerName -- rm -rf /poll-log
done
NOW_TIME=`date +%Y%m%d_%H-%M-%S`
echo "Now -> $NOW_TIME"
mv $TX_NO ups_$NOW_TIME
echo "build package : ups_$NOW_TIME.tar.gz"
tar czvf ups_$NOW_TIME.tar.gz ups_$NOW_TIME
rm -rf ups_$NOW_TIME
